//
#include "stdafx.h"
#include "MainCommand.h"
#include "VisualStudioApp.h"
#include "VisualStudioView.h"


CMainCommand::CMainCommand(void)
{

}


CMainCommand::~CMainCommand(void)
{

}


void CMainCommand::OnNewFile()
{
	CVisualStudioView *pView = new CVisualStudioView();
	CComPtr<saf::IMdiContainer>	pMdiContainer;

	CComPtr<saf::IMainFrames>	pMainFrames;
	CComPtr<saf::IMainFrame>	pMainFrame;
	theApp.GetComFramework()->get_MainFrames(&pMainFrames);
	//pMainFrames->get_ActiveMainFramme(&pMainFrame);
	pMainFrame->get_MdiContainer(&pMdiContainer);
	pMdiContainer->InsertItem(-1, L"VisualStudioApp.cpp", 0, (saf::IDataView*)pView, NULL);
}


void CMainCommand::OnToolsMacrosExplorer()
{
	//CComPtr<safScript::IMacrosDrivers>	pMacrosDrivers;
	//HRESULT hr = E_FAIL;

	//hr = pMacrosDrivers.CoCreateInstance(safScript::CLSID_MacrosDrivers);
	//if (S_OK == hr)
	//{
	//	pMacrosDrivers->DoView();
	//	pMacrosDrivers.Detach();
	//}
}


void CMainCommand::OnHelp(UINT nCmdID, saf::ICommandItem *pCmdUI)
{

}


void CMainCommand::OnAppExit(UINT nCmdID, saf::ICommandItem *pCmdUI)
{
	theApp.GetComFramework()->Quit();
}


void CMainCommand::OnFounctionSplicationWnd(UINT nCmdID, saf::ICommandItem *pCmdUI)
{
	CComQIPtr<saf::ISplitterWnd>	pSplitterWnd;
//	CComQIPtr<saf::ISplitterCell>	pLeftCell;
	CComQIPtr<saf::IGenericPanel>	pGenericPanel;
	HRESULT hr = E_FAIL;

	SAF_TRY;

	//hr = theApp.GetMainFrame()->get_SplitterWnd(&pSplitterWnd);
	//ASSERT_COM(hr);

	//hr = pSplitterWnd->
	//ASSERT_COM(hr);
	//if (S_OK != hr)
	//{
	//	MessageBox(0, L"", L"", MB_OK);
	//	return ;
	//}

	CComQIPtr<saf::IGenericPanels>	pGenericPanels;
	hr = saf::_SafBaseModule->GetComFramework()->get_GenericPanels(&pGenericPanels);
	hr = pGenericPanels->get_Item(CComVariant(TITLE_LEFTCELL), &pGenericPanel);
//	pLeftCell->get_GenericPanel(&pGenericPanel);
	ASSERT_COM(hr);
	if (S_OK != hr)
	{
		MessageBox(0, L"", L"", MB_OK);
		return ;
	}

	CComQIPtr<saf::ICommandBars>	pCommandBars;
	CComQIPtr<saf::ICommandBar>		pCommandBar;

	CComBSTR	strTitle(TITLE_LEFTCELL);
	strTitle += L"CommandBar";
	pGenericPanel->CreateCommandBars(strTitle, &pCommandBars);
	pCommandBars->InsertResourceCommandBar(L"ToolBar", IDR_MAINFRAME, (LONG_PTR)SafGetInstanceHandle(), 0, &pCommandBar);

	pGenericPanel->UpdateLayout();

	SAF_CATCH_NO_RETURN;
}


void CMainCommand::OnAbout(UINT nCmdID, saf::ICommandItem *pCmdUI)
{
	::MessageBox(::GetActiveWindow(), _T("About VisualStudio"), _T("VisualStudio"), MB_OK);
}


void CMainCommand::OnQueryAppExit(saf::ICommandItem *pCmdUI)
{
	pCmdUI->put_Enable(VARIANT_TRUE);
}


void CMainCommand::OnQueryHelp(saf::ICommandItem *pCmdUI)
{
	pCmdUI->put_Enable(VARIANT_TRUE);
}


void CMainCommand::OnQueryAppAbout(saf::ICommandItem *pCmdUI)
{
	pCmdUI->put_Enable(VARIANT_TRUE);
}


void CMainCommand::OnViewThemeSetup()
{
	//CComQIPtr<saf::ITheme> pTheme;
	//if (S_OK == theApp.GetComFramework()->get_Theme((IDispatch**)&pTheme))
	//{
	//	pTheme->DoSetup(GetActiveWindow());
	//}
}


void CMainCommand::OnViewSetupLanguage()
{
	theApp.GetComFramework()->DoLanguageDialg(GetActiveWindow());
}

//HWND operator wireHWND(wireHWND hWnd)
//{
//	return hWnd;
//}